package com.mingqijia.gassafety.console.controller;

import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.shared.constant.OperateRecordEnum;
import com.mingqijia.gassafety.shared.log.LogRecord;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.webserver.request.*;
import com.mingqijia.gassafety.webserver.response.*;
import com.mingqijia.gassafety.webserver.service.FunctionAreaService;
import com.mingqijia.gassafety.webserver.service.ServicePkgRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 服务套餐
 * @Author: duanhongxiang
 * @Date: 2024/6/12 16:54
 */
@Slf4j
@RestController
@Api(tags = "服务套餐")
@RequestMapping("/business/v1/service/pkg")
public class ServicePkgRecordController {

    @Autowired
    private ServicePkgRecordService servicePkgRecordService;


    @ApiOperation(value = "服务套餐-列表")
    @PostMapping("/list")
    public CommonResponse<PageUtil<ServicePkgRecordListResp>> businessAreaList(@RequestBody ServicePkgRecordListReq req) {

        return CommonResponse.success(servicePkgRecordService.businessAreaList(req));
    }


    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_76, detail = "'新增【' + #req.pgkName + '】'", commonInfo ="#req.pgkName")
    @ApiOperation(value = "服务套餐-新增")
    @PostMapping("/add")
    public CommonResponse<Boolean> add(@RequestBody @Valid ServicePkgRecordReq req) {

        return CommonResponse.success(servicePkgRecordService.add(req));
    }

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_77)
    @ApiOperation(value = "服务套餐-编辑")
    @PostMapping("/edit")
    public CommonResponse<Boolean> edit(@RequestBody @Valid ServicePkgRecordReq req) {

        return CommonResponse.success(servicePkgRecordService.edit(req));
    }

    @ApiOperation(value = "服务套餐-详情")
    @GetMapping("/detail")
    public CommonResponse<ServicePkgRecordListResp> detail(@RequestParam
                                              @ApiParam(value = "id", required = true) Integer id) {
        log.info("id:{}", id);
        if (null == id) {
            return CommonResponse.failure("id不能为空");
        }
        return CommonResponse.success(servicePkgRecordService.detail(id));
    }

    @LogRecord(operateType = OperateRecordEnum.OPERATE_TYPE_78)
    @ApiOperation(value = "服务套餐-删除")
    @PostMapping("/delete")
    public CommonResponse<Boolean> delete(@RequestBody @Valid FuncAreaIdRequest req) {
        if (null == req.getId()) {
            return CommonResponse.failure("id不能为空");
        }
        return CommonResponse.success(servicePkgRecordService.delete(req));
    }

    @ApiOperation(value = "服务套餐-服务内容")
    @GetMapping("/serviceContent")
    public CommonResponse<List<ServicePkgRecordContentResp>> serviceContent() {
        return CommonResponse.success(servicePkgRecordService.serviceContent());
    }

    @ApiOperation(value = "服务套餐-校验是否存在客户")
    @GetMapping("/checkConsumer")
    public CommonResponse<Integer> checkConsumer(@RequestParam
                                                           @ApiParam(value = "id", required = true) Integer id) {
        log.info("id:{}", id);
        if (null == id) {
            return CommonResponse.failure("id不能为空");
        }
        return CommonResponse.success(servicePkgRecordService.checkConsumer(id));
    }
}
